/*   1:    */ package org.intellij.plugins.relaxNG.xml.dom.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.XmlElementFactory;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlText;
import com.intellij.util.IncorrectOperationException;
import org.intellij.plugins.relaxNG.xml.dom.RngGrammar;
import org.jetbrains.annotations.NotNull;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */ 
/*  20:    */ class CreatePatternFix
/*  21:    */   implements IntentionAction, LocalQuickFix
/*  22:    */ {
/*  23:    */   private final PsiReference a;
/*  24:    */   
/*  25:    */   public CreatePatternFix(PsiReference paramPsiReference)
/*  26:    */   {
/*  27: 47 */     this.a = paramPsiReference;
/*  28:    */   }
/*  29:    */   
/*  30:    */   @NotNull
/*  31:    */   public String getText()
/*  32:    */   {
/*  33: 52 */     String tmp32_26 = ("Create Pattern '" + this.a.getCanonicalText() + "'");
/*  34: 52 */     if (tmp32_26 == null) {
/*  35: 52 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "getText" }));
/*  36:    */     }
/*  37: 52 */     return tmp32_26;
/*  38:    */   }
/*  39:    */   
/*  40:    */   @NotNull
/*  41:    */   public String getFamilyName()
/*  42:    */   {
/*  43: 57 */     String tmp2_0 = "Create Pattern";
/*  44: 57 */     if (tmp2_0 == null) {
/*  45: 57 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "getFamilyName" }));
/*  46:    */     }
/*  47: 57 */     return tmp2_0;
/*  48:    */   }
/*  49:    */   
/*  50:    */   @NotNull
/*  51:    */   public String getName()
/*  52:    */   {
/*  53: 62 */     String tmp4_1 = getText();
/*  54: 62 */     if (tmp4_1 == null) {
/*  55: 62 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "getName" }));
/*  56:    */     }
/*  57: 62 */     return tmp4_1;
/*  58:    */   }
/*  59:    */   
/*  60:    */   public void applyFix(@NotNull Project paramProject, @NotNull ProblemDescriptor paramProblemDescriptor)
/*  61:    */   {
/*  62: 66 */     if (paramProject == null) {
/*  63: 66 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "applyFix" }));
/*  64:    */     }
/*  65: 66 */     if (paramProblemDescriptor == null) {
/*  66: 66 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "applyFix" }));
/*  67:    */     }
/*  68: 66 */     if (!a()) {
/*  69: 67 */       return;
/*  70:    */     }
/*  71:    */     try
/*  72:    */     {
/*  73: 70 */       b();
/*  74:    */     }
/*  75:    */     catch (IncorrectOperationException localIncorrectOperationException)
/*  76:    */     {
/*  77: 72 */       Logger.getInstance(getClass().getName()).error(localIncorrectOperationException);
/*  78:    */     }
/*  79:    */   }
/*  80:    */   
/*  81:    */   public boolean isAvailable(@NotNull Project paramProject, Editor paramEditor, PsiFile paramPsiFile)
/*  82:    */   {
/*  83: 77 */     if (paramProject == null) {
/*  84: 77 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "isAvailable" }));
/*  85:    */     }
/*  86: 77 */     return a();
/*  87:    */   }
/*  88:    */   
/*  89:    */   private boolean a()
/*  90:    */   {
/*  91: 81 */     if ((!(this.a instanceof DefinitionReference)) || (!this.a.getElement().isValid())) {
/*  92: 82 */       return false;
/*  93:    */     }
/*  94: 84 */     RngGrammar localRngGrammar = ((DefinitionReference)this.a).getScope();
/*  95: 85 */     if (localRngGrammar == null) {
/*  96: 86 */       return false;
/*  97:    */     }
/*  98: 87 */     if (localRngGrammar.getXmlTag() == null) {
/*  99: 88 */       return false;
/* 100:    */     }
/* 101: 90 */     return true;
/* 102:    */   }
/* 103:    */   
/* 104:    */   public void invoke(@NotNull Project paramProject, Editor paramEditor, PsiFile paramPsiFile)
/* 105:    */     throws IncorrectOperationException
/* 106:    */   {
/* 107: 95 */     if (paramProject == null) {
/* 108: 95 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/xml/dom/impl/CreatePatternFix", "invoke" }));
/* 109:    */     }
/* 110: 95 */     b();
/* 111:    */   }
/* 112:    */   
/* 113:    */   private void b()
/* 114:    */     throws IncorrectOperationException
/* 115:    */   {
/* 116: 99 */     XmlTag localXmlTag1 = (XmlTag)PsiTreeUtil.getParentOfType(this.a.getElement(), XmlTag.class);
/* 117:100 */     assert (localXmlTag1 != null);
/* 118:101 */     XmlTag localXmlTag2 = localXmlTag1.createChildTag("define", "http://relaxng.org/ns/structure/1.0", "\n \n", false);
/* 119:102 */     localXmlTag2.setAttribute("name", this.a.getCanonicalText());
/* 120:    */     
/* 121:104 */     RngGrammar localRngGrammar = ((DefinitionReference)this.a).getScope();
/* 122:105 */     if (localRngGrammar == null) {
/* 123:105 */       return;
/* 124:    */     }
/* 125:106 */     XmlTag localXmlTag3 = localRngGrammar.getXmlTag();
/* 126:107 */     if (localXmlTag3 == null) {
/* 127:107 */       return;
/* 128:    */     }
/* 129:109 */     XmlTag[] arrayOfXmlTag1 = localXmlTag3.getSubTags();
/* 130:110 */     for (XmlTag localXmlTag4 : arrayOfXmlTag1) {
/* 131:111 */       if (PsiTreeUtil.isAncestor(localXmlTag4, localXmlTag1, false))
/* 132:    */       {
/* 133:112 */         XmlElementFactory localXmlElementFactory = XmlElementFactory.getInstance(localXmlTag1.getProject());
/* 134:113 */         XmlText localXmlText = localXmlElementFactory.createDisplayText(" ");
/* 135:114 */         PsiElement localPsiElement = localXmlTag3.addAfter(localXmlText, localXmlTag4);
/* 136:    */         
/* 137:116 */         localXmlTag3.addAfter(localXmlTag2, localPsiElement);
/* 138:117 */         return;
/* 139:    */       }
/* 140:    */     }
/* 141:120 */     localXmlTag3.add(localXmlTag2);
/* 142:    */   }
/* 143:    */   
/* 144:    */   public boolean startInWriteAction()
/* 145:    */   {
/* 146:124 */     return true;
/* 147:    */   }
/* 148:    */   
/* 149:    */   public static XmlTag getAncestorTag(XmlTag paramXmlTag, String paramString1, String paramString2)
/* 150:    */   {
/* 151:128 */     if (paramXmlTag == null) {
/* 152:129 */       return null;
/* 153:    */     }
/* 154:131 */     if ((paramXmlTag.getLocalName().equals(paramString1)) && (paramXmlTag.getNamespace().equals(paramString2))) {
/* 155:132 */       return paramXmlTag;
/* 156:    */     }
/* 157:134 */     return getAncestorTag(paramXmlTag.getParentTag(), paramString1, paramString2);
/* 158:    */   }
/* 159:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.xml.dom.impl.CreatePatternFix

 * JD-Core Version:    0.7.0.1

 */